<template>
  
	<div id="cash">
	    <yd-cell-group>
	    	<div class="title h3 ">提现金额</div>
	        <yd-cell-item>
	            <span class="h2" slot="left">¥：</span>
	            <yd-input type="number" slot="right" v-model="money" ref="money"
	             placeholder="提现金额"></yd-input>
	        </yd-cell-item>
	        <div class="tip" 
	        v-if="money == '' || money == 0">
		        当前余额{{maxMoney}}元 , 
		        <span class="getall red" v-on:click="getall">提取全部</span>
	       	</div>
	       	<div class="tip" 
	       	v-if="!(money == '' || parseFloat(money) == 0) && parseFloat(money) < 1">
		        <span class="red">最低提现1元</span>
	       	</div>
	       	<div class="tip" v-if="parseFloat(money) > maxMoney">
		        <span class="red">输入金额超过可提现金额</span>
	       	</div>
	       	<!-- <div class="tip" 
	       	v-if="1 <= parseFloat(money) && parseFloat(money) <= maxMoney ">
		        <span class="">
		        额外扣除¥{{parseFloat(parseFloat(money) * 0.005).toFixed(2)}}手续费(费率0.5%)</span>
	       	</div> -->
	    </yd-cell-group>

<!-- 	    <yd-cell-group >
	    	<div class="title h3 ">提现方式</div>
	        <yd-cell-item type="radio">
	            <span slot="left">提现到微信</span>
	            <input slot="right" type="radio" value="1" v-model="getMoneyType"/>
	        </yd-cell-item>

	        <yd-cell-item type="radio">
	            <span slot="left">提现到银行卡</span>
	            <input slot="right" type="radio" value="2" v-model="getMoneyType" disabled/>
	        </yd-cell-item>
	    </yd-cell-group> -->


		<yd-button-group class="mb20">
	        <yd-button @click.native="cash" size="large" type="primary"
	        :disabled="check">提现</yd-button>
	    </yd-button-group>

	</div>


</template>

<script>

import { mapGetters } from 'vuex'

export default {
	name: 'Cash',
	data () {
		return {
			money : '',
			getMoneyType : 1,
		}
	},

	computed : {
		...mapGetters([
			'company_code',
			'userdata',
		]),

		maxMoney () {
			return this.$route.query.max_money;
		},

		check () {
			console.log('this.money');
			console.log(this.money);
			if(this.money < 1){
				//this.money = 0;
				return true;
			}

			if(parseFloat(this.money) > this.maxMoney){
				return true;
			}
			return false;
		},
	},

	mounted () {
		this._setFocusHander();
	},

	methods : {
		getall () {
			this.money = this.maxMoney;
		},

		_setFocusHander() {
            this.$refs.money.setFocus();
        },

        cash () {
			this.$store.dispatch('cash', {
	  			'price' : parseFloat(this.money).toFixed(2),
	  			'callback' : (code) => {
	  				this.$router.push({ 
						'name': 'cashsuccess', 
						'query' : { 
							'company_code' : this.company_code,
							'code' : code,
						}
					});
	  			},
	  			'error' : msg => {
	  				this.$dialog.toast({
	                    mes: msg,
	                    timeout: 1500,
	                    icon: 'error',
	                });
	  			},
	  		});
		}
	}
}
</script>

<style scoped>

#cash {
	padding: 20px 0;
	/*background-color: #fff;*/
}

.title {
	/*margin-top: 20px;*/
	padding: 10px 20px;
}

.tip {
	color: #999;
	padding: 10px 20px;
}

.tip .getall {
	/*color: red;*/
}

</style>
